package 读写锁;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * @program: algorithm
 * @description: 锁降级demo
 * @author: 陈恩涛
 * @create: 2022-09-14 16:49
 **/
public class LockDownGradingDemo {

    public static void main(String[] args) {

        final ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
        final Lock readLock = readWriteLock.readLock();
        final Lock writeLock = readWriteLock.writeLock();

        readLock.lock();
        System.out.println("读取");

        writeLock.lock();
        System.out.println("写入");

        writeLock.unlock();
        readLock.unlock();

    }
}
